/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Navigation.java
 *
 * Created on Feb 24, 2010, 6:11:17 PM
 */

package dat215projekt.gui.components;

import java.awt.CardLayout;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import org.jdesktop.application.Action;

/**
 *
 * @author Administrator
 */
public class Navigation extends javax.swing.JPanel {

    private JPanel panelen;
    private JTabbedPane pane;
    private int state = 0; // HomePanel

    /** Creates new form Navigation */
    public Navigation() {
        initComponents();

        ButtonGroup ett = new ButtonGroup();
        ett.add(butikButton);
        ett.add(cartButton);
        ett.add(checkoutButton);

        butikButton.setSelected(true);
        updateSelection();


    }

    public void setPanelRef(JPanel panelen){
        this.panelen = panelen;
    }

    public void setPaneRef(JTabbedPane pane){
        this.pane = pane;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        previousButton = new javax.swing.JButton();
        butikButton = new javax.swing.JToggleButton();
        cartButton = new javax.swing.JToggleButton();
        checkoutButton = new javax.swing.JToggleButton();
        nextButton = new javax.swing.JButton();

        setName("Form"); // NOI18N
        setOpaque(false);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(dat215projekt.Dat215projektApp.class).getContext().getActionMap(Navigation.class, this);
        previousButton.setAction(actionMap.get("previousPage")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(dat215projekt.Dat215projektApp.class).getContext().getResourceMap(Navigation.class);
        previousButton.setIcon(resourceMap.getIcon("previousButton.icon")); // NOI18N
        previousButton.setBorderPainted(false);
        previousButton.setContentAreaFilled(false);
        previousButton.setName("previousButton"); // NOI18N
        add(previousButton);

        butikButton.setAction(actionMap.get("goToShop")); // NOI18N
        butikButton.setIcon(resourceMap.getIcon("butikButton.icon")); // NOI18N
        butikButton.setText(resourceMap.getString("butikButton.text")); // NOI18N
        butikButton.setBorderPainted(false);
        butikButton.setContentAreaFilled(false);
        butikButton.setName("butikButton"); // NOI18N
        butikButton.setSelectedIcon(resourceMap.getIcon("butikButton.selectedIcon")); // NOI18N
        add(butikButton);

        cartButton.setAction(actionMap.get("goToshoppingCart")); // NOI18N
        cartButton.setIcon(resourceMap.getIcon("cartButton.icon")); // NOI18N
        cartButton.setText(resourceMap.getString("cartButton.text")); // NOI18N
        cartButton.setBorderPainted(false);
        cartButton.setContentAreaFilled(false);
        cartButton.setName("cartButton"); // NOI18N
        cartButton.setSelectedIcon(resourceMap.getIcon("cartButton.selectedIcon")); // NOI18N
        add(cartButton);

        checkoutButton.setAction(actionMap.get("goToCheckout")); // NOI18N
        checkoutButton.setIcon(resourceMap.getIcon("checkoutButton.icon")); // NOI18N
        checkoutButton.setText(resourceMap.getString("checkoutButton.text")); // NOI18N
        checkoutButton.setBorderPainted(false);
        checkoutButton.setContentAreaFilled(false);
        checkoutButton.setName("checkoutButton"); // NOI18N
        checkoutButton.setSelectedIcon(resourceMap.getIcon("checkoutButton.selectedIcon")); // NOI18N
        add(checkoutButton);

        nextButton.setAction(actionMap.get("goToNextPage")); // NOI18N
        nextButton.setIcon(resourceMap.getIcon("nextButton.icon")); // NOI18N
        nextButton.setText(resourceMap.getString("nextButton.text")); // NOI18N
        nextButton.setBorderPainted(false);
        nextButton.setContentAreaFilled(false);
        nextButton.setName("nextButton"); // NOI18N
        add(nextButton);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void previousPage() {
        if(state > 0){
            ((CardLayout)panelen.getLayout()).previous(panelen);
            
            state -= 1;
            updateSelection();
        }
    }

    @Action
    public void goToShop() {
        ((CardLayout)panelen.getLayout()).first(panelen);
        state = 0;
        updateSelection();
    }

    @Action
    public void goToshoppingCart() {
       ((CardLayout)panelen.getLayout()).show(panelen, "card4");
       state = 1;
       updateSelection();
    }

    @Action
    public void goToCheckout() {
        ((CardLayout)panelen.getLayout()).last(panelen);
        state = 2;
        updateSelection();
    }

    @Action
    public void goToNextPage() {
         if(state < 2){
            ((CardLayout)panelen.getLayout()).next(panelen);

            state += 1;
            updateSelection();
        }
    }

    private void updateSelection(){
        switch(state){
            case 0: butikButton.setSelected(true); 
                    previousButton.setEnabled(false); 
                    nextButton.setEnabled(true);
                    break;
            case 1: cartButton.setSelected(true);
                    previousButton.setEnabled(true);
                    nextButton.setEnabled(true);
                    break;
            case 2: checkoutButton.setSelected(true);
                    previousButton.setEnabled(true);
                    nextButton.setEnabled(false);
                    break;
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton butikButton;
    private javax.swing.JToggleButton cartButton;
    private javax.swing.JToggleButton checkoutButton;
    private javax.swing.JButton nextButton;
    private javax.swing.JButton previousButton;
    // End of variables declaration//GEN-END:variables

}
